package baseTest;

import java.util.ArrayList;
import java.util.List;

public class permute {
    public static void main(String[] args) {
        int[] nums = {1,2,3,4};
        List<List<Integer>> lists = process(nums);
        for(List<Integer> list : lists){
            for (int n:list) {
                System.out.print(n);
            }
            System.out.println();
        }
    }
    public static List<List<Integer>> process(int[] nums){
        List<List<Integer>> lists = new ArrayList<>();
        process(nums,nums.length-1,nums.length-1,lists);
        return lists;
    }
    public static void process(int[] nums, int k,int n,List<List<Integer>> lists) {
        if ( k == 0){
            List<Integer> list = new ArrayList<>();
            for (int i:nums) {
                list.add(i);
            }
            lists.add(list);
        }

        for (int i = n-k; i <=n; i++) {
            swap(nums,n-k,i);
            process(nums,k-1,n,lists);
            swap(nums,n-k,i);
        }
    }
    public static void swap(int[] nums,int l,int r){
        int temp = nums[l];
        nums[l] = nums[r];
        nums[r] = temp;
    }
}
